<template>
  <div class="app-container">
    <el-row>
      <el-col :span="6" class="tl-left-tree">
        <!-- 树 -->
        <el-input v-model="queryTreeParam.qry_name" placeholder="根据名称筛选" @keyup.enter.native="filterTree" ref="treeSearch">
          <el-button current-node-key="" slot="append" icon="el-icon-search" @click="filterTree"></el-button>
        </el-input>
        <el-scrollbar ref="treeScroll" :style="{ height: treeHeight + 'px' }" resizable-key="treeHeight" :resizable-reduce="20" :resizable-refs="['treeSearch']">
          <el-tree class="tl-tree" ref="tree" :data="treeData" node-key="id" :default-expand-all="false" highlight-current :expand-on-click-node="false" @node-click="doTreeQuery" :filter-node-method="filterTreeNode" :default-expanded-keys="expandIdList"></el-tree>
        </el-scrollbar>
      </el-col>
      <el-col :span="18">
        <el-row>
          <!-- 查询 -->
          <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
            <template slot="search">
              <el-form-item label="编码" prop="code">
                <el-input v-model="queryParam.qry_code" placeholder=""></el-input>
              </el-form-item>
              <el-form-item label="名称">
                <el-input v-model="queryParam.qry_name" placeholder=""></el-input>
              </el-form-item>
            </template>
          </tl-list-search>
        </el-row>
        <el-card>
          <el-row>
            <!-- 工具栏 -->
            <tl-list-toolbar ref="toolbar" :isDisplayAdd="isDisplayAdd" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" :isDisplayExport="false" :isDisplayDeleteBatch="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0"> </tl-list-toolbar>
          </el-row>
          <el-row ref="selector">
            <!-- 列表选择 -->
            <div class="table-alert-div">
              <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
                <template slot="title">
                  已选择&nbsp;<a style="font-weight: bold;">{{ selectedRowKeys.length }}</a
                  >项&nbsp;&nbsp;
                  <a style="font-weight: bold;margin-left: 24px" @click="doClearSelected">全部清空</a>
                </template>
              </el-alert>
            </div>
          </el-row>
          <el-row>
            <el-table ref="mainTable" class="tl-table" :height="tableHeight" resizable-key="tableHeight" :resizable-reduce="42" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" style="width: 100%;" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName" :default-sort="{ prop: 'code', order: 'ascending' }">
              <el-table-column type="selection" width="55px"></el-table-column>
              <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
              <el-table-column prop="code" label="编码" width="150px" sortable="custom" sort-by="code" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="name" label="名称" width="150px" sortable="custom" sort-by="name" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="dispflowid" label="流程id" width="100px" sortable="custom" sort-by="flowid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="dispnodeid" label="流程节点id" width="100px" sortable="custom" sort-by="nodeid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="dispurltype" label="文件地址类型" width="100px" sortable="custom" sort-by="urltype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="url" label="文件地址" width="150px" sortable="custom" sort-by="url" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="version" label="文件最新版本号" width="150px" sortable="custom" sort-by="version" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="lastupdatetime" label="文件最后更新时间" width="170px" sortable="custom" sort-by="lastupdatetime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="dispoperatetype" label="操作类型" width="100px" sortable="custom" sort-by="operatetype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
                  <el-tag v-else type="danger">否</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
                <el-dropdown trigger="hover">
                  <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
                  <el-dropdown-menu>
                    <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
                    <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
                    <el-dropdown-item icon="el-icon-delete" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-table-column>
            </el-table>
          </el-row>
          <!-- 列表分页 -->
          <el-row class="pagebar" ref="pager">
            <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
          </el-row>
        </el-card>
      </el-col>
      <!-- 编辑界面 -->
      <tl-edit ref="editForm" @refresh="doAllRefresh" :flow-id="this.selectTreeNode.pid" :node-id="this.selectTreeNode.id" :disp-flow-id="this.selectTreeNode.hasOwnProperty('treeFullData') && this.selectTreeNode.treeFullData.hasOwnProperty('dispflowid') ? this.selectTreeNode.treeFullData.dispflowid : ''" :disp-node-id="this.selectTreeNode.name"></tl-edit>
    </el-row>
  </div>
</template>
<script>
/** mixins */
import { mixin_tree_list } from "@tapui/mixins/mixin_tree_list"
import { TreeQueryMode } from "@tapui/const/tapConst"
import { filterObjectNull } from "@tapui//utils/util"
/** 子组件 */
import tlEdit from "./edit"
import { putAction, getAction, postAction, deleteAction } from "@tapui/utils/http"
export default {
  name: "baseFlowFile",
  mixins: [mixin_tree_list],
  components: { tlEdit },
  data() {
    return {
      urlPrefix: "/base/flowFile/",
      url: {
        // queryCodeList: '/base/flowFile/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: "code",
        sord: "asc"
      },
      isDisplayAdd: true,
      // treeFiltersInfo: {
      //   flow_id: '',
      //   node_id: ''
      // },
      filtersInfo: {
        flow_id: "",
        node_id: ""
      },
      expandIdList: [0],
      // 数列表关联字段
      treeQueryKey: "qry_parentid"
    }
  },
  watch: {
    selectTreeNode: {
      handler(newValue, oldValue) {
        if (newValue.hasOwnProperty("treeFullData") && newValue.treeFullData.hasOwnProperty("canselected") && newValue.treeFullData.canselected === true) {
          this.isDisplayAdd = true
        } else {
          this.isDisplayAdd = false
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    // 打开新增对话框之后
    afterOpenAddDialog(editForm, rowData) {
      if (rowData) {
        this.$set(this.$refs[editForm].model, "dispparentid", rowData.name)
        this.$set(this.$refs[editForm].model, "parentid", rowData.id)
      } else {
        if (this.selectTreeNode && this.selectTreeNode.id > 0) {
          this.$set(this.$refs[editForm].model, "dispparentid", this.selectTreeNode.name)
          this.$set(this.$refs[editForm].model, "parentid", this.selectTreeNode.id)
        }
      }
      this.closeLoading()
    },
    /** 树节点点击 */
    doTreeQuery(treeNode) {
      // 查询方式为树节点查询
      this.treeQueryMode = TreeQueryMode.TreeDlick
      this.selectTreeNode = treeNode
      if (this.selectTreeNode.treeFullData.hasOwnProperty("canselected") && this.selectTreeNode.treeFullData.canselected === true) {
        // this.treeFiltersInfo.flow_id = this.selectTreeNode.treeFullData.flowid
        // this.treeFiltersInfo.node_id = this.selectTreeNode.treeFullData.id
        this.filtersInfo.flow_id = this.selectTreeNode.treeFullData.flowid
        this.filtersInfo.node_id = this.selectTreeNode.treeFullData.id
        this.pageInfo.currentPage = 1
        this.loadList({})
      } else {
        this.filtersInfo.flow_id = this.selectTreeNode.treeFullData.id
        this.filtersInfo.node_id = ''
        this.loadList({})
      }
      this.closeLoading()
    },
    openEditDialog(editForm, id) {
      this.$refs[editForm].id = id
      this.$refs[editForm].isAdd = false
      this.$refs[editForm].visible = true
      this.$refs[editForm].disableEditSubmit = false
      let that = this
      setTimeout(() => {
        that.clickRowkey = id
        this.closeLoading()
      }, 100)
    },
    /** 打开查看界面 */
    openViewDialog(editForm, id) {
      this.$refs[editForm].id = id
      this.$refs[editForm].isAdd = false
      this.$refs[editForm].visible = true
      this.$refs[editForm].disableEditSubmit = true
      let that = this
      setTimeout(() => {
        that.clickRowkey = id
        this.closeLoading()
      }, 100)
    },
    /** 加载树数据 */
    loadTree() {
      if (!this.url.queryTree) {
        this.$tap.alert("请设置树查询地址!", "warning")
        return
      }
      return getAction(this.url.queryTree, this.queryTreeParam).then((res) => {
        if (res.success) {
          this.treeData = []
          this.treeData = res.result.dataList
          if (this.treeData && this.treeData[0] && this.treeData[0].children && this.treeData[0].children[0] && this.treeData[0].children[0].id) {
            this.expandIdList.push(this.treeData[0].children[0].id)
          }
        } else {
          this.$tap.alert(res.message, "warning")
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped></style>
